{
 Ivanov Nikita
 10/09/2012
 Mass-sorting from file to file.
}
program MassSort;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
 i,j,n,s,t: integer;
 mass: array of integer;

begin
  writeln('Your mass will be sorted in output-file.');

  assignFile(input,'input.txt');
  assignFile(output,'output.txt');
  reset(input);
  readln(input, n);
  setlength(mass, n);
  for i:=0 to n-1 do
    read(input, mass[i]);
  for j:=0 to n-1 do
  begin
    s:=j;
    for i:=j+1 to n do
    begin
      if (mass[i]>=mass[s]) then
        s:=i;
    end;
  t:=mass[j];
  mass[j]:=mass[s];
  mass[s]:=t;
  end;
  rewrite(output);
  for i:=0 to n-1 do
    write(output, mass[i], ' ');
  readln;
end.
